package com.jic.member.controller.manage;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.common.util.BeanUtil;
import com.jic.member.entity.Meinformation;
import com.jic.member.request.MeinformationRequest;
import com.jic.member.response.MeinformationResponse;
import com.jic.member.service.MeinformationService;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author: zxl
 * @date: 2020-01-09
 * @remark:  会员消息
 */
@RestController
@RequestMapping("/memberInformation")
public class MemberInformationController {

    @Autowired
    MeinformationService meinformationService;

    /**
     * 分页查询
     * @param form
     * @return
     */
    @ApiOperation(value = "获取所有会员消息列表")
    @ResponseBody
    @RequestMapping("/queryInformationList")
    public RestResult<PageResult<MeinformationResponse>> queryList(@RequestBody MeinformationRequest form) {
        Page page = new Page();
        page.setLimit(form.getLimit());
        page.setStart(form.getStart());
        Meinformation memberAddress = BeanUtil.copy(form, Meinformation.class);
        PageResult<Meinformation> result = meinformationService.queryPage(memberAddress, page);
        List<MeinformationResponse> memberInformationResponseList = result.getRows().stream().map(temp -> {
            MeinformationResponse memberInformationResponse = BeanUtil.copy(temp, MeinformationResponse.class);
            return memberInformationResponse;
        }).filter(item -> item != null).collect(Collectors.toList());
        PageResult<MeinformationResponse> pageResult = new PageResult<>();
        pageResult.setRows(memberInformationResponseList);
        pageResult.setTotal(result.getTotal());
        return RestResult.success(pageResult);
    }

    @ApiOperation(value = "添加会员消息")
    @ResponseBody
    @RequestMapping("/editInformation")
    public RestResult editInformation(@RequestBody MeinformationRequest form){
        Meinformation memberInformation= BeanUtil.copy(form, Meinformation.class);
        return meinformationService.insertInformation(memberInformation);
    }

    @ApiOperation(value = "查询会员消息单个")
    @ResponseBody
    @RequestMapping("/queryMemberInformationInfo")
    public RestResult queryMemberInformationInfo(@RequestBody MeinformationRequest form){
        return meinformationService.queryMemberInformationInfo(form);
    }
}
